package com.example.demo.Controller;


import com.example.demo.bean.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController//交由spring管理
@Api(tags="用户管理")
@RequestMapping("/User")
public class UserController {
   //注入service对象
   @Autowired
   private com.example.demo.service.userService userService;
    @PostMapping("/Deleteuser")
    @ApiOperation(value = "删除用户信息", notes = "根据用户名删除信息")
    @ResponseBody
    public int Deleteuser(@RequestParam("username") String username){
        userService.Deleteuser(username);return 1;
    }
    @PostMapping("/Updateuser")
    @ApiOperation(value = "更新用户信息", notes = "根据用户名更新信息")
    @ResponseBody
    public  int Updateuser(@RequestParam("username") String username, @RequestParam("password") String password,@RequestParam("role") int role){
         userService.Updateuser(username,password,role);return 1;
    }
    @PostMapping("/selectsUser")
    @ApiOperation(value = "用户登录信息", notes = "根据账号密码登录")
    @ResponseBody
    public int selectsUser(@RequestParam("password") String password, @RequestParam("username") String username ){
        int role=userService.selectsUser(username, password).getRole();
         if(role ==1)
         {
             return 1;
         }
         return 0;
    }

    @PostMapping("/InsertUser")
    @ApiOperation(value = "注册用户信息", notes = "根据插入新用户信息")
    @ResponseBody
    public int InsertUser(@RequestParam("password") String password, @RequestParam("username") String username) {
         userService.InsertUser(username, password);
         return 1;
    }
    @PostMapping("/user")
    @ApiOperation(value = "获取所有用户信息", notes = "获取用户列表")
    @ResponseBody
    public List<User> Show(){
        return userService.selectUser();
    }
}



